package cn.yl.caner.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.yl.caner.domain.DelData;
import cn.yl.caner.service.DelService;

public class DelServlet extends HttpServlet {
	//注销账户
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置状态码
				int i = 0;
				request.setCharacterEncoding("UTF-8");
				//获取前端来的request
				String username = request.getParameter("del_username");
				String password = request.getParameter("del_password");
				String del_account = request.getParameter("del_hidden");
				//检验
				System.out.println(del_account+"666");
				DelData deldata = new DelData();
				deldata.setDel_username(username);
				deldata.setDel_hidden(del_account);
				System.out.println("隐藏用户"+del_account);
				if(username.equals(del_account)) {
					DelService delservice =  new DelService();
					String repassword = delservice.rePassword(deldata);
					System.out.println("删除的帐号和密码"+repassword+","+password);
					if(repassword.equals(password)) {
						i = delservice.delAccount(deldata);
						//状态返回代码判断
						if(i != 1) {
							System.out.println("删除失败");
							response.sendRedirect(request.getContextPath()+"/findfail.jsp");
						}else {
							System.out.println("删除成功");
							response.sendRedirect(request.getContextPath()+"/success.html");
						}

					}else {
						System.out.println("密码不正确");
						response.sendRedirect(request.getContextPath()+"/findfail.jsp");
					}
				}else {
					System.out.println("用户名与当前用户不匹配");
					response.sendRedirect(request.getContextPath()+"/findfail.jsp");
				}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}